import { Controller } from "../../mvc/core/Controller";
import { IPrizeFallModule } from "../../../modules/interfaces/IPrizeFallModule";
import { PrizeFallModule } from "../../../modules/PrizeFallModule";
import { IView } from "../../mvc/interfaces/IView";
import { PrizeFallHintBtn } from "../view/PrizeFall/PrizeFallHintBtn";
import { PrizeFallCrossHintBtn } from "../view/PrizeFall/PrizeFallCrossHintBtn";
import { PrizeFallCrossFireWorkHintBtn } from "../view/PrizeFall/PrizeFallCrossFireWorkHintBtn";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { PrizeFallCrossWindow } from "../view/PrizeFall/PrizeFallCrossWindow";
import { Language } from "../../../extend/language/Language";
import { DataEvent } from "../events/DataEvent";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SAttribute } from "../../../Message/Public/SAttribute";
import { MapIdRule } from "../rules/MapIdRule";
import { FlowerManager } from "../../../extend/flash/flower/FlowerManager";
import { FlowerType } from "../../../extend/flash/flower/FlowerType";
import { ResFileConst } from "../resource/ResFileConst";
//class PrizeFallController
    
    export  class PrizeFallController extends Controller
    {
       

        public get prizeFall(): IPrizeFallModule
        {
            if (null == this._prizeFall) 
            {
                this._prizeFall = new PrizeFallModule();
            }
            return this._prizeFall;
        }

        public /* override */ get view(): IView
        {
            return this.prizeFall;
        }

        public get prizeFallHintBtn(): PrizeFallHintBtn
        {
            if (!this._prizeFallHintBtn) 
            {
                this._prizeFallHintBtn = new PrizeFallHintBtn();
            }
            return this._prizeFallHintBtn;
        }

        public get prizeFallCrossHintBtn(): PrizeFallCrossHintBtn
        {
            if (!this._prizeFallCrossHintBtn) 
            {
                this._prizeFallCrossHintBtn = new PrizeFallCrossHintBtn();
            }
            return this._prizeFallCrossHintBtn;
        }

        public get prizeFallCrossFireWorkHintBtn(): PrizeFallCrossFireWorkHintBtn
        {
            if (!this._prizeFallCrossFireWorkHintBtn) 
            {
                this._prizeFallCrossFireWorkHintBtn = new PrizeFallCrossFireWorkHintBtn();
            }
            return this._prizeFallCrossFireWorkHintBtn;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            Dispatcher.addEventListener(EventName.PrizeFallShowModule, this.onPrizeFallShowModule);
            Dispatcher.addEventListener(EventName.PrizeFallCrossShowModule, this.onPrizeFallCrossShowModule);
            Dispatcher.addEventListener(EventName.PrizeFallCrossFireWorkShowModule, this.onPrizeFallCrossFireWorkShowModule);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicPrizeFallOpen, this.onPrizeFallOpen);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicPrizeFallClose, this.onPrizeFallClose);
            return;
        }

        public get prizeFallCrossFireWorkWin(): PrizeFallCrossWindow
        {
            if (null == this._prizeFallCrossFireWorkWin) 
            {
                this._prizeFallCrossFireWorkWin = new PrizeFallCrossWindow();
            }
            this._prizeFallCrossFireWorkWin.setDesTx(Language.getString(70759));
            this._prizeFallCrossFireWorkWin.setTile(Language.getString(70760));
            return this._prizeFallCrossFireWorkWin;
        }

        /* internal  */onPrizeFallCrossFireWorkShowModule(arg1: DataEvent): void
        {
            if (this.prizeFallCrossFireWorkWin.isHide) 
            {
                this.prizeFallCrossFireWorkWin.show();
            }
            else 
            {
                this.prizeFallCrossFireWorkWin.hide();
            }
            return;
        }

        public get prizeFallCrossWin(): PrizeFallCrossWindow
        {
            if (null == this._prizeFallCrossWin) 
            {
                this._prizeFallCrossWin = new PrizeFallCrossWindow();
            }
            this._prizeFallCrossWin.setDesTx(Language.getString(70758));
            this._prizeFallCrossWin.setTile(Language.getString(70757));
            return this._prizeFallCrossWin;
        }

        /* internal  */onPrizeFallCrossShowModule(arg1: DataEvent): void
        {
            if (this.prizeFallCrossWin.isHide) 
            {
                this.prizeFallCrossWin.show();
            }
            else 
            {
                this.prizeFallCrossWin.hide();
            }
            return;
        }

        /* internal  */onPrizeFallShowModule(arg1: DataEvent): void
        {
            var loc1="";
            if (arg1.data) 
            {
                loc1 = arg1.data as string;
            }
            if (this.prizeFall.isHide) 
            {
                this.prizeFall.show();
            }
            else 
            {
                this.prizeFall.hide();
            }
            if (!(loc1 == "") && loc1) 
            {
                this.prizeFall.updateDesc(loc1);
            }
            return;
        }

        /* internal  */onPrizeFallOpen(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SAttribute;
            if (loc1) 
            {
                if (loc1.value != MapIdRule.TaijiCity) 
                {
                    if (loc1.value == MapIdRule.CrossMainCity) 
                    {
                        if (cache.role.roleInfo.level < 70) 
                        {
                            return;
                        }
                        if (loc1.valueStr != "firework") 
                        {
                            if (loc1.valueStr == "") 
                            {
                                FlowerManager.instance.addFlowerQueue(FlowerType.PrizeFall, 15000, ResFileConst.PrizeFall);
                                this.onStarFallPrizeCross();
                            }
                        }
                        else 
                        {
                            FlowerManager.instance.addFlowerQueue(FlowerType.PrizeFall, 15000, ResFileConst.PrizeFall);
                            this.onStarFallPrizeCrossFireWork();
                        }
                    }
                }
                else 
                {
                    FlowerManager.instance.addFlowerQueue(FlowerType.PrizeFall, 15000, ResFileConst.PrizeFall);
                    this.onStarFallPrize();
                }
            }
            return;
        }

        /* internal  */onPrizeFallClose(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SAttribute;
            if (loc1) 
            {
                if (loc1.value != 400101) 
                {
                    if (loc1.value == 900502) 
                    {
                        if (loc1.valueStr != "firework") 
                        {
                            if (loc1.valueStr == "") 
                            {
                                this.removePrizeFallCross();
                            }
                        }
                        else 
                        {
                            this.removePrizeFallCrossFireWork();
                        }
                    }
                }
                else 
                {
                    this.removeConsumeCountActive();
                }
            }
            return;
        }

        /* internal  */onStarFallPrize(): void
        {
            this.prizeFallHintBtn.show();
            this.prizeFallHintBtn.highLight();
            return;
        }

        /* internal  */onStarFallPrizeCross(): void
        {
            this.prizeFallCrossHintBtn.show();
            this.prizeFallCrossHintBtn.highLight();
            return;
        }

        /* internal  */onStarFallPrizeCrossFireWork(): void
        {
            this.prizeFallCrossFireWorkHintBtn.show();
            this.prizeFallCrossFireWorkHintBtn.highLight();
            return;
        }

        /* internal  */removeConsumeCountActive(): void
        {
            if (this._prizeFallHintBtn) 
            {
                this._prizeFallHintBtn.hide();
            }
            if (this._prizeFall) 
            {
                this._prizeFall.hide();
            }
            return;
        }

        /* internal  */removePrizeFallCross(): void
        {
            if (this._prizeFallCrossHintBtn) 
            {
                this._prizeFallCrossHintBtn.hide();
            }
            if (this._prizeFallCrossWin) 
            {
                this._prizeFallCrossWin.hide();
            }
            return;
        }

        /* internal  */removePrizeFallCrossFireWork(): void
        {
            if (this._prizeFallCrossFireWorkHintBtn) 
            {
                this._prizeFallCrossFireWorkHintBtn.hide();
            }
            if (this._prizeFallCrossFireWorkWin) 
            {
                this._prizeFallCrossFireWorkWin.hide();
            }
            return;
        }

        private /* var */_prizeFall: IPrizeFallModule;

        private /* var */_prizeFallHintBtn: PrizeFallHintBtn;

        private /* var */_prizeFallCrossHintBtn: PrizeFallCrossHintBtn;

        private /* var */_prizeFallCrossFireWorkHintBtn: PrizeFallCrossFireWorkHintBtn;

        private /* var */_prizeFallCrossFireWorkWin: PrizeFallCrossWindow;

        private /* var */_prizeFallCrossWin: PrizeFallCrossWindow;
    }
